﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Diagnostics;
using System.Threading;
using InSimDotNet;
using InSimDotNet.Packets;
using InSimDotNet.Out;
using System.Collections;
using System.Text.RegularExpressions;
using System.Timers;
using System.Configuration;


namespace lfsserver6
{
    public class conf
    {
        //Global configuration variables
        public static string ip;
        public static string port;
        public static string password;
        public static string filename;
        handler handler = new handler();

        //Configurationfile reader. Read insim initalization values from conf.cfg file
        public void ConfigurationReader()
        {

            string confIp = String.Empty;
            string confPort = String.Empty;
            string confPassword = String.Empty;
            string confFilename = String.Empty;

            string path = "conf.cfg";

            var dictionary = File.ReadLines(path).Skip(13)
                           .Select(line => line.Split(new[] { '=' }, 2))                           
                           .Where(split => split.Length == 2)
                           .ToDictionary(split => split[0], split => split[1]);

            if (dictionary.ContainsKey("HostIP"))
                confIp = dictionary["HostIP"];
            handler.set_conf_ip(confIp);

            if (dictionary.ContainsKey("Port"))
                confPort = dictionary["Port"];
            handler.set_conf_port(confPort);

            if (dictionary.ContainsKey("AdminPassword"))
                confPassword = dictionary["AdminPassword"];
            handler.set_conf_password(confPassword);

            if (dictionary.ContainsKey("LogFile"))
                confFilename = dictionary["LogFile"];            
            handler.set_conf_filename(confFilename);


        }



    }
}
